//
//  UIBarButtonItem+Extension.swift
//  小荣荣新浪微博
//
//  Created by zzr on 2018/4/20.
//  Copyright © 2018年 zzr. All rights reserved.
//

import UIKit
extension UIBarButtonItem {
    
    
    /// 创建UiBarButtonItem
    ///
    /// - Parameters:
    ///   - title: 名称
    ///   - fontSize: 字体大小默认16
    ///   - target: 目标
    ///   - action: 动作
    ///   - isBack: 是否返回按钮，是就加上箭头图标
    convenience init(title: String, fontSize: CGFloat = 18, target: Any?, action: Selector, isBackButton: Bool = false) {
        let btn = UIButton()
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        btn.tintColor = UIColor.orange
        btn.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        if isBackButton {
            btn.setImage(UIImage(named: "navigationbar_back_withtext"), for: .normal)
            btn.setImage(UIImage(named: "navigationbar_back_withtext_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        self.init(customView: btn)
    }
    
}
